package com.voice.client;

import com.voice.client.message.MessageClient;
import com.voice.client.message.MessageClientFactory;
import com.voice.client.message.callback.MessageCallback;
import com.voice.client.message.entity.Message;
import com.voice.core.utils.MessageUtil;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


//@SpringBootApplication
public class VoiceClientApplication {

    public static void main(String[] args) throws IOException {
        //SpringApplication.run(VoiceClientApplication.class, args);
        Profile profile = Profile.getAppKeyProfile("http://voice.emlab.net:8081", "24842048", "5b64076769d9c92e0169d9ccbd0jkh7f");

        MessageClient messageClient = MessageClientFactory.messageClient(profile);
        messageClient.connect(message -> {
            System.out.println(message);
            return MessageCallback.Action.CommitSuccess;
        });
        messageClient.publishServerPort(8082);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str;
        do {
            str = reader.readLine();
            Message message=new Message(str.getBytes(), MessageUtil.messageId(),0);
            messageClient.publish("/test",message);
        } while (!str.equalsIgnoreCase("byebye"));
        messageClient.disconnect();
    }
}
